package com.bawei.park2302.park

import com.bawei.lib_base.utils.utils.mvi.BaseViewModel
import com.bawei.lib_base.utils.utils.request.RequestType
import com.bawei.lib_base.utils.utils.utils.ApiService
import dagger.hilt.android.lifecycle.HiltViewModel
import javax.inject.Inject

@HiltViewModel
class ParkViewModel @Inject constructor(val apiService: ApiService) : BaseViewModel<ParkIntent>() {
    override fun handelIntent(it: ParkIntent) {
        when(it){
            is ParkIntent.parkSpaceStatus -> pagingRequest {
                ParkDataSource(apiService,it.spaceStatus,"状态")
            }

            is ParkIntent.parkSpaceType -> pagingRequest {
                ParkDataSource(apiService,it.spaceType,"类型")
            }

            is ParkIntent.parkArea -> pagingRequest {
                ParkDataSource(apiService,it.area,"区域")
            }

            is ParkIntent.parkLicensePlate -> pagingRequest {
                ParkDataSource(apiService,it.licensePlate,"车牌号")
            }

            is ParkIntent.parkAdd -> httpRequest(apiService.parkAdd(mapToBody(it.parkBeanItem)))

            is ParkIntent.parkSpaces -> httpRequest(apiService.parkSpaces(it.id,mapToBody(it.parkBeanItem)),RequestType.SPACE)

            is ParkIntent.parkDetail -> httpRequest(apiService.parkDetail(it.id))
        }
    }
}